package main

import (
	"bufio"
	"fmt"
	"learning/goclac/lexer"
	"learning/goclac/parser"
	"os"
	"strconv"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	for {
		fmt.Printf("=> ")
		arrBytes, _, err := reader.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		line := strings.TrimSpace(string(arrBytes))

		expression := line
		tokens, e := lexer.Parse(expression)
		if e != nil {
			println(e.Error())

		} else {
			e,v := parser.Parse(tokens)
			if e != nil {
				println(e.Error())
			}

			fmt.Println(strconv.FormatFloat(v, 'f', 10, 64))
		}
	}
}
